<template>
  <div class="account">
    <div class="shang">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>条件查询</span>
        </div>

        <el-form
          :inline="true"
          :model="formInline"
          size="mini"
          class="demo-form-inline"
        >
          <el-row>
            <el-col :span="6">
              <el-form-item label="订单编号">
                <el-input
                  v-model="formInline.orderSn"
                  placeholder="请输入订单编号"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="退单状态">
                <el-select
                  v-model="formInline.status"
                  placeholder="请选退单状态"
                >
                  <el-option label="待处理" value="0" />
                  <el-option label="退货中" value="1" />
                  <el-option label="已完成" value="2" />
                  <el-option label="已拒绝" value="3" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="19">
              <el-form-item />
            </el-col>
            <el-col :span="4">
              <el-form-item>
                <el-button type="primary" @click="chaxun">查询</el-button>
                <el-button @click="chonzhi">重置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </div>

    <div class="xia">
      <el-table :data="list" border style="width: 100%">
        <el-table-column type="index" label="#" width="50" />
        <el-table-column prop="orderSn" label="订单编号" width="180" />
        <el-table-column prop="status" label="退单状态" width="180">
          <template v-slot="sisui">
            <el-tag
              v-if="sisui.row.status === 0"
              style="color: #fff"
              color="#fa0000"
            >
              待处理
            </el-tag>
            <el-tag
              v-else-if="sisui.row.status === 1"
              style="color: #fff"
              color="#d48721"
            >
              退货中
            </el-tag>
            <el-tag
              v-else-if="sisui.row.status === 2"
              style="color: #fff"
              color="#1c94c4"
            >
              已完成
            </el-tag>
            <el-tag v-else style="color: #fff" color="#e05151"> 已拒绝 </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="description" label="描述" width="180" />
        <el-table-column prop="reason" label="退单原因" width="180" />
        <el-table-column prop="productName" label="商品名称" width="180" />

        <el-table-column prop="productAttr" label="商品属性" width="180">
          <template v-slot="sisui">
            <div>

              <div v-for="(item,index) in sisui.row.productAttr" :key="index" style="height:25px;overflow: hidden">
                {{ item.key }}--{{ item.value }}
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="handleNote" label="商家备注" width="180" />
        <el-table-column prop="createTime" label="添加时间" width="180" />
        <el-table-column type="" fixed="right" label="操作" width="180">
          <el-button type="primary" icon="el-icon-aim">查看订单</el-button>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="start"
      :page-sizes="[1, 5, 10, 15]"
      :page-size="limit"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { findReturnApply } from '@/api/order/unwinding/index.js'
export default {
  data() {
    return {
      shuxing: '',
      // 请求的数据
      list: [],
      start: 1,
      limit: 10,
      total: 0,
      formInline: {
        createTime: '',
        handleTime: '',
        memberUsername: '',
        orderId: '',
        orderSn: '',
        status: ''
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      findReturnApply(this.start, this.limit, this.formInline).then((res) => {
        console.log(res)
        res.data.rows.forEach((ele) => {
          ele.productAttr = JSON.parse(ele.productAttr)
          console.log(ele.productAttr)
          if (!Array.isArray(ele.productAttr)) {
            ele.productAttr = [{
              key: '别瞎传',
              value: '妈蛋的'
            }]
          }
        })
        this.list = res.data.rows
        console.log(this.list)
        this.total = res.data.total
      })
    },
    // 点击重置按钮
    chonzhi() {
      this.formInline = {
        createTime: '',
        handleTime: '',
        memberUsername: '',
        orderId: '',
        orderSn: '',
        status: ''
      }
      this.init()
    },
    // 点击查询
    chaxun() {
      this.init()
    },
    // 点击条数/页触发请求新数据
    handleSizeChange(e) {
      this.limit = e
      this.init()
    },
    // 点击页数发送请求新数据
    handleCurrentChange(e) {
      this.start = e
      this.init()
    }
  }
}
</script>

<style lang="scss" scoped>
.account {
  margin: 30px;
  .shang {

  }
  .xia {
    text-align: center;
    margin-top: 30px;
    .zhengcahng {
      width: 100px;
      height: 100%;
      color: #fa0000;
      background-color: #e2b6b6;
      text-align: center;
      border: 1px solid #41f31e;
    }
  }
}
</style>
